package com.qf.purchasing.controller;

import com.github.pagehelper.PageInfo;
import com.qf.common.base.result.RespResult;
import com.qf.purchasing.qo.AuditQueryQO;
import com.qf.purchasing.service.AgentService;
import com.qf.purchasing.service.AuditService;
import com.qf.purchasing.vo.AuditVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/Audit")
//类上，tags=模块名
@Api(tags = "采购审核")
public class AuditController {
    @Resource
    private AuditService auditService;
    @Resource
    private AgentService agentService;

    @GetMapping("/list")
    @ApiOperation("条件分页展示申请审核记录")
    @ApiImplicitParams({
            //                参数名，       参数说明，         是否必填， 参数请求类型：query,header,path  参数数据类型，   参数默认值           示例
            @ApiImplicitParam(name = "page", value = "当前页数", required = false, paramType = "query", dataType = "java.lang.Integer", defaultValue = "1", example = "page=1"),
            @ApiImplicitParam(name = "size", value = "展示量", required = false, paramType = "query", dataType = "java.lang.Integer", defaultValue = "5"),
            @ApiImplicitParam(name = "title", value = "搜索标题", required = false, paramType = "query", dataType = "java.lang.String"),
            @ApiImplicitParam(name = "agentName", value = "审核人", required = false, paramType = "query", dataType = "java.lang.String"),
            @ApiImplicitParam(name = "linkName", value = "当前环节", required = false, paramType = "query", dataType = "java.lang.String"),
            @ApiImplicitParam(name = "startTime", value = "开始日期", required = false, paramType = "query", dataType = "java.lang.String"),
            @ApiImplicitParam(name = "endTime", value = "结束日期", required = false, paramType = "query", dataType = "java.lang.String"),

    })
    public RespResult<PageInfo<AuditVO>> list(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "5") int size, AuditQueryQO auditQueryQO) {
        return auditService.query(page, size, auditQueryQO);
    }

    @PutMapping("/delete")
    @ApiOperation("审核采购申请")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "auditIds", value = "id数组", required = true)
    )
    public RespResult<String> audit(int[] auditIds) {
        return auditService.auditByIds(auditIds);
    }

    @GetMapping("/audit")
    @ApiOperation("已审核列表")
    public RespResult<List<AuditVO>> auditList() {
        return auditService.queryAuditList();
    }

    @GetMapping("/notAudit")
    @ApiOperation("待审核列表")
    public RespResult<List<AuditVO>> notAuditList() {
        return auditService.queryNotAuditList();
    }


    @GetMapping("/show")
    @ApiOperation("回显经办人名称给前端")
    public RespResult<List<String>> selectAgents() {
        return agentService.queryName();
    }

}
